<div class="content-box">

    <div class="content-box-header">

        <h3><?=t_lang('manager_user')?></h3>

        <ul class="content-box-tabs">
            <li><a href="#tab1" class="default-tab"><?=t_lang('users')?></a></li>
            <li><a href="#tab2"><?=t_lang('permission')?></a></li>
        </ul>

        <div class="clear"></div>

    </div> <!-- End .content-box-header -->

    <div class="content-box-content">

        <div class="tab-content default-tab" id="tab1">
           <form action="" method="post" id="frm_index"> 
           <table class="global_table">

                <thead>
                    <tr>
                       <!--<th><input class="check-all" type="checkbox" /></th>-->
                       <th><?=t_lang('user_name')?></th>
                       <th><?=t_lang('group_name')?></th>
                       <th><?=t_lang('full_name')?></th>
                       <th><?=t_lang('user_email')?></th>
                       <th><?=t_lang('status')?></th>
                       <th><?=t_lang('action')?></th>
                    </tr>

                </thead>

                <tbody>
                    <?php if(count($users)) : ?>
                        <?php foreach($users as $user) : ?>
                            <tr>
                                <!--<td><input type="checkbox" class="sl_check" name="sl[]" value="<? //=$l['id']?>" /></td>-->
                                <td><a href="<?=$txt['a_edit'] . $user['user_id']?>" title="Edit"><?=$user['user_name']?></a></td>
                                <td>
                                    <select id="user_group_<?=$user['user_id']?>" onchange="s_group('<?=$user['user_id']?>')">
                                        <?php if($groups && !empty($groups)) : ?>
                                            <?php foreach($groups as $group) :?>
                                                    <option value="<?=$group->user_group_id?>" <?php if($user['user_group'] == $group->user_group_id) echo "selected=selected";?>"><?=$group->user_group_name?></option>
                                            <?php endforeach ?>
                                        <?php endif ?>
                                	</select>
                                </td>
                                <td><?=$user['user_full']?></td>
                                <td><?=$user['user_email']?></td>
                                <td>
                                    <select id="change_status_<?=$user['user_id']?>" onchange="s_status('<?=$user['user_id']?>')">
                                        <?php if($user['user_active'] == 1) : ?>
                                            <option value="1" selected="selected"><?=t_lang('active')?></option>
                                        <?php else : ?>
                                            <option value="1"><?=t_lang('active')?></option>
                                        <?php endif ?>
                                         <?php if($user['user_active'] == 0) : ?>
                                            <option value="0" selected="selected"><?=t_lang('unactive')?></option>
                                        <?php else : ?>
                                            <option value="0"><?=t_lang('unactive')?></option>
                                        <?php endif ?>    
                                    </select>
                                    
                                </td>
                                <td>
                                    <!--Icons-->
                                     <a  href="<?=$txt['a_edit'] . $user['user_id']?>" title="Edit"><img src="<?=base_url('themes/admin/images/icons/pencil.png')?>" alt="Edit" /></a>
                                     <a href="javascript:void(0);" onClick="doDel('<?=$user['user_id']?>')" title="Delete"><img src="<?=base_url('themes/admin/images/icons/cross.png')?>" alt="Delete" /></a>
                                </td>
                            </tr>
                        <?php endforeach ?>
                    <?php endif ?>
                </tbody>
                
                
                <tfoot>
                    <tr>
                        <td colspan="6">
                            <div class="bulk-actions align-left">
                                <!--<a class="button" href="javascript:void(0);" onClick="checkDel();"><? //=t_lang('btn_del')?></a>-->
                                <a class="button" href="<?=$txt['a_add']?>"><?=t_lang('btn_create_new')?></a>
                            </div>
                            
                            <?php if( isset($pages) && $pages !='') : ?>
                            <div class="pagination">                           
                               <?php echo $pages; ?>
                                
                            </div> <!-- End .pagination -->
                            <div class="clear"></div>
                            <?php endif ?>
                        </td>
                    </tr>
                </tfoot>
                
            </table>
           </form><!--End #form_index-->    
        </div> <!-- End #tab1 -->
        
        <div class="tab-content" id="tab2">
           
             
        </div> <!-- End #tab2 -->
        
    </div> <!-- End .content-box-content -->

</div> <!-- End .content-box -->


<script>
    
    jQuery(document).ready(function(){
       loadListGroup(); 
    });
    
    
    function loadListGroup()
    {
        jQuery('#tab2').load('<?=$txt['link_load_group']?>');
    }
    
    function checkDel()
    {
        var listID = $('input:checkbox:checked.sl_check').map(function() {
            return this.value;
        }).get();
        
        if(listID == '')
        {
            alert('<?=t_lang('please_choose_a_item')?>');
            return false;
        } else {
            if(confirm('<?=t_lang('confirm_delete')?>'))
            {
                $('#frm_index').submit();
            }
        }
    }
    
    function doDel(id)
    {
        if(confirm('<?=t_lang('confirm_delete')?>'))
        {
           $.ajax({
                type: "POST",
                dataType: "json",
                data: "id=" + id,
                url: '<?=$txt['a_del']?>',
                success: function(data)
                {
                    if(data)
                    {                
                        alert(data.message);
                        loadList();
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
    }
    
    function doDelGroup(id)
    {
        if(confirm('<?=t_lang('confirm_delete')?>'))
        {
           $.ajax({
                type: "POST",
                dataType: "json",
                data: "id=" + id,
                url: '<?=$txt['a_del_group']?>',
                success: function(data)
                {
                    if(data)
                    {                
                        alert(data.message);
                        loadListGroup();
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
    }
    
    function s_status(lang_id)
    {
        var id = $('#change_status_' + lang_id).val();
        $.ajax({
                type: "POST",
                dataType: "json",
                data: "id=" + id + "&langId=" + lang_id,
                url: '<?=$txt['a_change_status']?>',
                success: function(data)
                {
                    if(data)
                    {                
                        alert(data.message);
                    } else {
                        alert(data.message);
                    }
                }
            });
    }
    
    function s_group(lang_id)
    {
        var id = $('#user_group_' + lang_id).val();
        $.ajax({
                type: "POST",
                dataType: "json",
                data: "groupId=" + id + "&userId=" + lang_id,
                url: '<?=$txt['a_change_group']?>',
                success: function(data)
                {
                    if(data)
                    {                
                        alert(data.message);
                    } else {
                        alert(data.message);
                    }
                }
            });
    }
</script>